
let equipmentDao = require('../model/backend/equipment');
//封装客户端socket连接相关处理事件

exports.clientSocket = function(socket){
  try {
      let query = socket.request._query;
      let mac =query.mac;
  //设备信息验证
      let valicationSocketequipmnet  =  equipmentDao.valicationSocketequipmnet(mac);
      if(valicationSocketequipmnet.length===0){
        socket.emit(mac,'设备未在系统注册，请注册！')
        socket.disconnect(true);
        return;
      }
      //记录设备最新连接时间 
      let connectTime = new Date();
       //equipmentDao.updateEquipmentOnlineStatus(mac,'y',connectTime);

      socket.emit(mac,'连接成功!')

       console.log('一台编号为'+mac+'设备连接');

    //设备掉线处理
    socket.on("disconnect", function() {
      let disconnectTime = new Date();
       //equipmentDao.updateEquipmentDisconnectStatus(mac,'n',disconnectTime);
      console.log('编号为',mac,"掉线！");
    });
  } 
  catch (error) {
   console.log(error) 
  }
}
